<?php

namespace App\Kuafu\Mqtt\Command;

use App\Kuafu\Mqtt\Model\Log;
use Illuminate\Console\Command;

class RemoveLogCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'mqtt:removeLog';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '定时清理日志';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command
     * 定时清理 7 天前的 mqtt 日志
     */
    public function handle()
    {
        Log::query()->where('createdAt', '<',  time() - 86400 * 3)->delete();
    }
}
